package com.yanqu.xiuxian.crosssystem.manger.elementalbonds.logic;

import com.yanqu.xiuxian.config.elementalbonds.enums.ElementalBondsEffectType;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity.ElementalBondsBlock;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity.ElementalBondsOperateEffect;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity.ElementalBondsOperateShow;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.param.ElementalBondsCardParam;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.param.ElementalBondsMoveParam;
import com.yanqu.xiuxian.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ElementalBondsGuideLogic {

    // 客户端对话
    public static ElementalBondsOperateShow getClientShow(ElementalBondsEffectType elementalBondsEffectType, int no) {
        ElementalBondsOperateEffect elementalBondsOperateEffect = new ElementalBondsOperateEffect(elementalBondsEffectType);
        elementalBondsOperateEffect.setParam(no);
        ElementalBondsOperateShow elementalBondsOperateShow = new ElementalBondsOperateShow();
        elementalBondsOperateShow.addElementalBondsOperateEffect(elementalBondsOperateEffect);
        return elementalBondsOperateShow;
    }

    // 替换第一个效果（例：普通移动替换成新手引导移动）
    public static void replaceFirstEffect(List<ElementalBondsOperateShow> elementalBondsOperateShowList,
                                          ElementalBondsEffectType fromElementalBondsEffectType, ElementalBondsEffectType toElementalBondsEffectType) {
        boolean success = false;
        for (ElementalBondsOperateShow elementalBondsOperateShow : elementalBondsOperateShowList) {
            for (ElementalBondsOperateEffect elementalBondsOperateEffect : elementalBondsOperateShow.getElementalBondsOperateEffectList()) {
                if (elementalBondsOperateEffect.getEffectType() == fromElementalBondsEffectType.getType()) {
                    elementalBondsOperateEffect.setEffectType(toElementalBondsEffectType.getType());
                    success = true;
                    break;
                }
            }
            if (success) break;
        }
    }

    // 获取指定盘面
    public static List<List<ElementalBondsBlock>> getBlockList(boolean beforeGuide, boolean isPlayer1) {
        List<Integer> initBlockList;
        if (beforeGuide) {
            if (isPlayer1) {
                initBlockList = StringUtils.stringToIntegerList("4,1,6,2,6,1,5,1,3,4,4,3,2,6,2,5,1,5,1,5,5,4,4,3,4,6,2,3,5,3,6,3,1,3,2,6,2,4,1,6,6,1,2,5,3,5,3,4,4", ",");
            } else {
                initBlockList = StringUtils.stringToIntegerList("4,2,6,1,6,2,5,2,3,4,4,3,1,6,1,5,2,5,2,5,5,4,4,3,4,6,1,3,5,3,6,3,2,3,1,6,1,4,2,6,6,2,1,5,3,5,3,4,4", ",");
            }
        } else {
            if (isPlayer1) {
                initBlockList = StringUtils.stringToIntegerList("4,1,4,2,6,1,5,1,3,1,4,6,5,6,2,2,3,5,3,3,5,5,5,4,6,1,4,3,6,1,1,5,6,1,2,2,3,6,2,2,1,1,4,1,4,4,2,3,4", ",");
            } else {
                initBlockList = StringUtils.stringToIntegerList("4,2,4,1,6,2,5,2,3,2,4,6,5,6,1,1,3,5,3,3,5,5,5,4,6,2,4,3,6,2,2,5,6,2,1,1,3,6,1,1,2,2,4,2,4,4,1,3,4", ",");
            }
        }

        List<List<ElementalBondsBlock>> blockList = new ArrayList<>();
        int index = 0;
        for (int y = 0; y < 7; y++) {
            blockList.add(new ArrayList<>());
            for (int x = 0; x < 7; x++) {
                ElementalBondsBlock block = new ElementalBondsBlock();
                block.setX(x);
                block.setY(y);
                block.setColor(initBlockList.get(index++));
                blockList.get(y).add(block);
            }
        }
        return blockList;
    }

    // 获取使用卡片参数
    public static ElementalBondsCardParam getElementalBondsCardParam1(int cardId) {
        ElementalBondsCardParam elementalBondsCardParam = new ElementalBondsCardParam();
        elementalBondsCardParam.setCardId(cardId);
        elementalBondsCardParam.setSide(1);
        return elementalBondsCardParam;
    }

    // 获取移动参数
    public static ElementalBondsMoveParam getElementalBondsMoveParam(int no) {
        if (no == 1) {
            return new ElementalBondsMoveParam(2, 3, 2, 4);
        } else if (no == 2) {
            return new ElementalBondsMoveParam(2, 4, 2, 3);
        } else if (no == 3) {
            return new ElementalBondsMoveParam(3, 3, 4, 3);
        } else {
            return null;
        }
    }

    // 获取指定掉落颜色
    public static List<Integer> getDropColorList(int no) {
        if (no == 1) {
            return StringUtils.stringToIntegerList("1,3,2", ",");
        } else if (no == 2) {
            return StringUtils.stringToIntegerList("4,1,4", ",");
        } else if (no == 3) {
            return StringUtils.stringToIntegerList("1,6,2", ",");
        } else if (no == 4) {
            return StringUtils.stringToIntegerList("4,1,3,4,1,1,3,6,1,1,4,2,3", ",");
        }
        return new ArrayList<>();
    }

    // 获取技能效果
    public static Set<ElementalBondsBlock> getCard01Result(List<List<ElementalBondsBlock>> blockList) {
        Set<ElementalBondsBlock> elementalBondsBlockSet = new HashSet<>();
        elementalBondsBlockSet.add(blockList.get(1).get(4));
        elementalBondsBlockSet.add(blockList.get(1).get(5));
        elementalBondsBlockSet.add(blockList.get(2).get(1));
        elementalBondsBlockSet.add(blockList.get(3).get(2));
        elementalBondsBlockSet.add(blockList.get(3).get(5));
        elementalBondsBlockSet.add(blockList.get(5).get(1));
        elementalBondsBlockSet.add(blockList.get(5).get(5));
        return elementalBondsBlockSet;
    }

}
